﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XPathPlugin.XPathTreeUtils
{
    class XPathNodeList: List<XPathNode>
    {
        private XPathNode _parent;        

        public XPathNodeList(XPathNode parent)
        {
            _parent = parent;          
        }

        /// <summary>
        /// Gets or sets the parent of this node
        /// </summary>
        public XPathNode Parent
        {
            get { return _parent; }
            set { _parent = value; }
        }

        /// <summary>
        /// Add node to Parent children
        /// </summary>
        /// <param name="node">node to add</param>
        public new void Add(XPathNode node)
        {
            base.Add(node);
            node.Parent = _parent;
        }

        /// <summary>
        /// Add XPathValue new node to parent children
        /// </summary>
        /// <param name="value">value to add</param>
        public void Add(XPathValue value)
        {
            XPathNode node = new XPathNode(_parent);
            node.Value = value;
            base.Add(node);
        }

        /// <summary>
        /// Removes node from parent childern, Set node parent to null
        /// </summary>
        /// <param name="node">node to remove</param>
        /// <returns>bool - if removed</returns>
        public new bool Remove(XPathNode node)
        {
            if (node != null)
            {
                node.Parent = null;
            }
            return base.Remove(node);
        }
    }
}
